<template>
  <div class="product_list">
    <div class="page_img"></div>
    <div class="header">
      <van-nav-bar title="供应商增类" left-text="" left-arrow @click-left="goBack" />
    </div>
    <div style="" class="product_list_serch-text">
      <van-search class="product_list_serch1" v-model="searchValue" shape="round" background="#F6FAFF" >
        <template #left-icon>
            <div class="search_l_bt"></div>
        </template>
        <template #right-icon>
            <div class="search_r_bt" @click="onSearch">搜索</div>
        </template>
      </van-search>
     
    </div>
    <van-pull-refresh v-model="refreshing" class="pull_box" @refresh="onRefresh">
      <van-list v-model:loading="loading" :finished="finished" @load="onLoad">
        <template v-slot:finished>
          <div class="nothing_div" v-if="list.length == 0">
            <van-image :src="nothingData"></van-image>
            <div class="nothing_font">暂无数据</div>
          </div>
        </template>
        <div class="product_list_van_list">
          <div class="product_list_van_list_div_box" v-for="(item, index) in list" :key="index">
            <div  class="product_list_van_list_div"
              @click="handleGetDetails(item.id)">
              <div class="div_right">
                <div class="div_right_top">
                  <div class="style_name">
                    {{ item.supplierName }}
                  </div>
                </div>

                <div class="div_right_bottom">
                  <div class="div_right_bottom_div">
                    <div class="value">{{ item.productsCount }}</div>
                    <div class="label">商品总数</div>
                  </div>
                  <div class="b_line"> </div>
                  <div class="div_right_bottom_div">
                    <div class="value">{{ item.productsShopping }}</div>
                    <div class="label">上架总数</div>
                  </div>
                  <div class="b_line"> </div>
                  <div class="div_right_bottom_div">
                    <div class="value">{{ item.productsOpt }}</div>
                    <div class="label">选品数</div>
                  </div>
                </div>

                <div class="div_right_center">
                  <div class="contract">
                    <div :style="{
                      color: item.sellStatus == '1' ? '#19D11B' : '#FC2540',
                      backgroundColor: item.sellStatus == '1' ? '#E7FDEE' : '#FDE7E7',
                    }">
                      供销合同
                      <van-image class="van-image"
                      :src="item.sellStatus == '1' ? icon_duihaolvse : icon_wenhaohongse"></van-image>
                    </div>
                  </div>
                  <div class="contract_break">
                    <div :style="{
                      color: item.discountStatus == '1' ? '#19D11B' : '#FC2540',
                      backgroundColor: item.discountStatus == '1' ? '#E7FDEE' : '#FDE7E7',
                    }">
                      破价合同
                      <van-image class="van-image"
                      :src="item.discountStatus == '1' ? icon_duihaolvse : icon_wenhaohongse"></van-image>
                    </div>
                  </div>
                  <div class="contract_break">
                    <div :style="{
                      color: item.depositStatus == '1' ? '#19D11B' : '#FC2540',
                      backgroundColor: item.depositStatus == '1' ? '#E7FDEE' : '#FDE7E7',
                    }">
                      保证金协议
                      <van-image class="van-image"
                      :src="item.depositStatus == '1' ? icon_duihaolvse : icon_wenhaohongse"></van-image>
                    </div>
                  </div>
                </div>
                
              </div>
            </div>
            <div class="line"></div>
          </div>
        </div>
      </van-list>
    </van-pull-refresh>
  </div>
</template>
<script setup lang="ts">
import { computed, onMounted, ref, watch } from "vue";
import { hmSupplierList } from "@/api/supplierList/index";
import { useRoute, useRouter } from "vue-router";
const nothingData = new URL("@/assets/porduct/icon_zanwushuju.png", import.meta.url).href
const icon_duihaolvse = new URL("@/assets/productHome/icon_duihaolvse1.png", import.meta.url).href;
const icon_wenhaohongse = new URL("@/assets/newui/productList/icon_hongsecha@2x.png", import.meta.url).href;
const router = useRouter();
const route = useRoute()
const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
  supplierName: "",
});
const searchValue = ref("");

const refreshing = ref(false);
const loading = ref(false);
const finished = ref(false);
const list = ref<any[]>([]);

// 限制连续刷新数据重复问题
const refreFlag = ref(true)

/** 搜索 */
const onSearch = () => {
  queryParams.value.supplierName = searchValue.value;
  onRefresh();
};
/** 搜索供应商名称 */
const supplierName = computed(() => {
  return route.query.supplierName
})
watch(
  () => supplierName.value,
  (v: any) => {
    queryParams.value.supplierName = v;
    searchValue.value = v
  },
  { immediate: true }
);
/** 返回上一页 */
const goBack = () => {
  router.push('/addSupplier')
}
/** 获取详情 */
const handleGetDetails = (id: string) => {
  router.push({
    path: `/addSupplierClassAdd/${id}`,
    query: {
      supplierName: queryParams.value.supplierName
    }
  });
};
/** 查询商品列表 */
const getList = async () => {
  const res = await hmSupplierList(queryParams.value);
  refreFlag.value = true
  // 空数据 停止加载
  if (res.rows.length == 0) {
    list.value = [];
    finished.value = true;
    return;
  }
  // 有数据 赋值列表 加载状态结束
  res.rows.forEach((item) => {
    finished.value = false;
    list.value.push(item);
  });
  loading.value = false;
  refreshing.value = false;
  // 如果list长度大于等于总数据条数，数据全部加载完成
  if (list.value.length >= res.total) {
    finished.value = true; //结束加载
  }
};
/** 加载更多 */
const onLoad = async () => {
  getList();
  queryParams.value.pageNum++;
};
/** 下拉 */
const onRefresh = () => {
  if (refreFlag.value) {
    refreFlag.value = false
    finished.value = false; // 清空列表数据
    refreshing.value = false;
    loading.value = true; // 加载状态
    queryParams.value.pageNum = 1; // 分页数赋值为1
    list.value = []; // 清空数组
    onLoad(); // 重新加载数据
  } else {
    finished.value = false;
    refreshing.value = false;
  }
};
onMounted(() => { });
</script>
<style lang="less" scoped>
.product_list {
  width: 100%;
  height: 100vh;
  background-color: #fff;
  background: url("@/assets/newui/productList/icon_shangpinbeijing@2x.png");
  background-size: 100%;
  background-repeat: no-repeat;
  position: relative;

  .page_img {
      background: url("@/assets/newui/productList/supplierList@2x.png");
      background-size: 100% 100%;
      position: absolute;
      width: 60px;
      height: 60px;
      top: 52px;
      right: 63px;
  }

  :deep(.van-nav-bar__content) {
    background-color: #fff;
    height: 46px !important;
    width: 100%;
  }

  .header {
    filter: blur(0px);
    height: 90px;
    padding-top: 44px;
    box-sizing: border-box;
    width: 100%;
    position: relative;
    z-index: 6003;

    :deep(.van-icon-arrow-left) {
      color: #1a1b1c !important;
    }

    :deep(.van-nav-bar) {
      background: none !important;
      &::after{
          border:none;
      }
    }

    :deep(.van-nav-bar__content) {
      background-color: transparent !important;
    }
  }

  .nothing_div {
    width: 100%;
    margin: auto;
    text-align: center;
    margin-top: 20vh;
    font-weight: 400;
    font-size: 12px;
    color: #B8BECA;
    line-height: 12px;
    flex-wrap: wrap;

    .van-image {
      width: 160px;
      height: 160px;
    }

  }

  // overflow: hidden;
  .product_list_serch-text {
    display: flex;
    align-items: center;
    width: 100%;
    height: 50px;
    position: relative;
    box-sizing: border-box;
    padding: 0 15px;

    :deep(.van-search__field) {
      background-color: #fff;
      border-radius: 20px;
    }

    .product_list_serch1 {
      display: flex;
      align-items: center;
      width: 100%;
      height: 34px;
      padding: 0px;
      box-sizing: border-box;
      overflow: hidden;
      background-color: #fff;
      border: 1px solid #0094ff;
      border-radius: 20px;

      :deep(.van-search__content) {
        height: 35px;
        background-color: #fff;
      }

      :deep(.van-search__field) {
        height: 35px;
      }

      .search_l_bt {
          width: 14px;
          height: 14px;
          background-image: url("@/assets/newui/productList/icon_sousuo@2x.png");
          background-size: 100% 100%;
      }

      .search_r_bt {
          width: 54px;
          height: 26px;
          background: linear-gradient(146deg, #0064ff 0%, #008fff 100%);
          border-radius: 14px;
          font-weight: 500;
          font-size: 14px;
          color: #ffffff;
          line-height: 26px;
          text-align: center;
          transform: translateX(5px);
      }
    }
    
  }

  &_serch {
    display: flex;
    width: calc(100% - 20px);
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
    margin-top: 5px;
    margin-bottom: 5px;
    height: 23px;

    :deep(.van-image) {
      width: 20px;
      height: 20px;
    }

    &_item {
      border: 1px solid #a3a3a3;
      color: #a3a3a3;
      width: 60px;
      text-align: center;
      height: 20px;
      font-size: 12px;
      border-radius: 4px;
      line-height: 20px;
      overflow: hidden;
    }

    &_active {
      border: none !important;
      color: #fff;
      background-color: #1466ff;
    }
  }

  :deep(.van-pull-refresh) {
    height: calc(100vh - 140px);
    overflow: scroll;
  }

  :deep(.van-search) {
    background-color: #eeeeee;
  }

  .product_list_van_list {
    // min-height: calc(100vh - 140px);
    display: flex;
    align-items: center;
    justify-content: space-between;

    flex-direction: column;

    .line {
        height: 8px;
        background: #F6FAFF;
    }

    .product_list_van_list_div {
      width: 100%;
      box-sizing: border-box;
      background-color: #fff;
      padding: 15px;
      display: flex;
      justify-content: space-between;
    }

    .div_right {
      width: 100%;
      display: flex;
      flex-wrap: wrap;

      .div_right_top {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: space-between;

        .style_name {
          font-weight: 500;
          font-size: 16px;
          color: #1A1B1C;
          line-height: 16px;
        }

        .stats {
          text-align: center;
          border-radius: 3px;
          height: 22px;
          background: #EBF4FF;
          border-radius: 2px;
          line-height: 22px;
          font-weight: 500;
          font-size: 12px;
          color: #0094FF;
          min-width: 70px;
        }
      }

      .div_right_center {
        width: 100%;
        color: #a3a3a3;
        margin-top: 10px;
        font-size: 12px;
        display: flex;
        align-items: center;

        .contract {
          div {
            display: flex;
            justify-content: center;
            align-items: center;
            width: 105px;
            height: 22px;
            border-radius: 5px;

            .van-image {
                width: 12px;
                height: 12px;
                margin-left: 5px;
            }
          }
        }

        .contract_break {
          margin-left: 15px;

          div {
            display: flex;
            justify-content: center;
            align-items: center;
            width: 105px;
            height: 22px;
            border-radius: 5px;

            .van-image {
                width: 12px;
                height: 12px;
                margin-left: 5px;
            }
          }
        }
      }

      .div_right_bottom {
        display: flex;
        width: 100%;
        align-items: center;
        justify-content: space-between;
        margin-top: 7px;
        background: #F7F7F799;
        border-radius: 5px;
        box-sizing: border-box;
        padding: 10px 0;

        .b_line {
            width: 1px;
            height: 19px;
            background-color: #ECECF2;
        }

        .div_right_bottom_div {
          width: 0;
          flex: 1;
          display: flex;
          flex-direction: column;
          align-items: center;

          .label {
            font-weight: 400;
            font-size: 12px;
            color: #8492AD;
            line-height: 12px;
            text-align: left;
            font-style: normal;
            text-transform: lowercase;
            margin-top: 5px;
          }

          .value {
            font-weight: 500;
            font-size: 12px;
            color: #1A1B1C;
            line-height: 12px;
            text-align: left;
            font-style: normal;
          }
        }
      }
    }
  }
}
.pull_box{
    background: #FFFFFF;
    border-radius: 15px 15px 0px 0px;
    
}
.product_list_van_list_div_box{
    width: 100%;
}
</style>
